<?php
error_reporting("E_ALL");ini_set("display_errors", 1);
$getdata=$_REQUEST;
if(empty($getdata))$getdata=$_POST?$_POST:$_GET;
$type=empty($getdata['type'])?'':$getdata['type'];
$id=empty($getdata['id'])?'':$getdata['id'];
include("include/function.php");
//header("content-Type: application/json; charset=utf-8");
$config = include("config.php");
include("include/".$config['DB_TYPE'].".class.php");
$db = new db;
$db->connect($config['DB_HOST'],$config['DB_USER'],$config['DB_PWD'],$config['DB_NAME'], $config['DB_PCONNECT']);
$where="pay_status=20 and new_class_name<>'' and new_class_id=''";	
if($id){
    $where.=" and order_id>".$id;
}
$sql = "select * from hema_food_order where ".$where." order by order_id limit 1000";
$list = $db->get_all($sql);$insert=0;if(empty($list))exit('over');
$class=[];
foreach($list as $v){
    $sql = "select class_id from hema_school_class where school_id ='".$v['school_id']."' and name='".$v['new_class_name']."'";
    $info = $db->get_one($sql);
    if(!empty($info['class_id'])){$insert++;
        $db->query("update hema_food_order set new_class_id='".$info['class_id']."' where order_id=".$v['order_id']);
    }
   /*$db->query("update hema_school_class set school_uuid='".$v['uuid']."' where school_id=".$v['school_id']);  */
}
//$log = $id.'导入成功,：'.$insert.'条';$page=0;
//echo $log.'<script>location.href="?page='.$page.'&id='.$id.'";</script>';

//echo count($sqlarr)."\n";
//echo implode(";\n",$sqlarr);
?>